package com.roamer.audition.web.controller;

import com.roamer.audition.common.request.AuditionRecordDTO;
import com.roamer.audition.common.request.AuditionRecordPageQuery;
import com.roamer.audition.common.request.AuditionRecordSimpleQuery;
import com.roamer.audition.common.response.AuditionRecordDetailVO;
import com.roamer.audition.common.response.AuditionRecordVO;
import com.roamer.audition.common.service.AuditionRecordService;
import com.roamer.validator.gruop.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 面试计划 API
 *
 * @author roamer
 * @version V1.0
 * @date 2019-08-21 00:47
 */
@Api(tags = "面试计划 API")
@Slf4j
@RestController
@RequestMapping("/auditionRecords")
public class AuditionRecordController {

    private final AuditionRecordService auditionRecordService;

    public AuditionRecordController(AuditionRecordService auditionRecordService) {
        this.auditionRecordService = auditionRecordService;
    }

    @ApiOperation(value = "修改面试计划", notes = "修改原有面试计划")
    @ApiImplicitParams(@ApiImplicitParam(name = "id", paramType = "path", value = "面试计划ID"))
    @PutMapping(value = "/{id}", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public AuditionRecordVO updateAuditionRecord(@PathVariable Long id, @Validated(Update.class) @RequestBody
            AuditionRecordDTO auditionRecordDTO) {
        auditionRecordDTO.setId(id);
        return auditionRecordService.updateAuditionRecord(auditionRecordDTO);
    }

    @ApiOperation(value = "删除面试计划", notes = "删除面试计划")
    @ApiImplicitParams(@ApiImplicitParam(name = "id", paramType = "path", value = "面试计划ID"))
    @DeleteMapping(value = "/{id}")
    public void deleteAuditionRecord(@PathVariable Long id) {
        auditionRecordService.deleteAuditionRecord(id);
    }

    @ApiOperation(value = "面试计划详情", notes = "根据ID查询面试计划")
    @ApiImplicitParams(@ApiImplicitParam(name = "id", paramType = "path", value = "面试计划ID"))
    @GetMapping(value = "/{id}")
    public AuditionRecordVO getAuditionRecord(@PathVariable Long id) {
        return auditionRecordService.getAuditionRecord(id);
    }

    @ApiOperation(value = "面试计划分页列表", notes = "分页查询面试计划列表")
    @GetMapping(value = "/page")
    public Page<AuditionRecordVO> getAuditionRecordPage(@Validated AuditionRecordPageQuery auditionRecordPageQuery) {
        return auditionRecordService.getAuditionRecordPage(auditionRecordPageQuery);
    }

    @ApiOperation(value = "面试计划列表", notes = "首页显示近期面试计划列表")
    @GetMapping("/simple")
    public List<AuditionRecordDetailVO> getAuditionRecordList(
            @Validated AuditionRecordSimpleQuery auditionRecordSimpleQuery) {
        return auditionRecordService.getAuditionRecordList(auditionRecordSimpleQuery);
    }

}
